/*
============================================================================
 Name        : $(classname)View.cpp
 Author      : $(author)
 Copyright   : $(copyright)
 Description : C$(classname)View implementation
============================================================================
*/

// INCLUDE FILES
#include <aknviewappui.h>
#include <avkon.hrh>
#include <$(projectName).rsg>
#include "$(classname)View.h"
#include "$(classname)Container.h" 

#include "$(classname)View.hrh"

// Todo items:
// 
// 1. redefine view id in .h file
// 

C$(classname)View* C$(classname)View::NewL()
	{
	C$(classname)View* self = C$(classname)View::NewLC();
	CleanupStack::PopAndDestroy();
	return self;
	}
	
C$(classname)View* C$(classname)View::NewLC()
	{
	C$(classname)View* self = new (ELeave) C$(classname)View();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}


C$(classname)View::C$(classname)View()
	{
	}

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// C$(classname)View::ConstructL(const TRect& aRect)
// EPOC two-phased constructor
// ---------------------------------------------------------
//
void C$(classname)View::ConstructL()
	{		
	BaseConstructL( R_$(projectName$upper)_$(classname$upper)VIEW );
	}

// ---------------------------------------------------------
// C$(classname)View::~C$(classname)View()
// destructor
// ---------------------------------------------------------
//
C$(classname)View::~C$(classname)View()
	{
	if ( iContainer )
		{
		AppUi()->RemoveFromViewStack( *this, iContainer );
		}

	delete iContainer;
	}

// ---------------------------------------------------------
// TUid C$(classname)View::Id()
//
// ---------------------------------------------------------
//
TUid C$(classname)View::Id() const
	{
	return K$(classname)ViewId;
	}

// ---------------------------------------------------------
// C$(classname)View::HandleCommandL(TInt aCommand)
// takes care of view command handling
// ---------------------------------------------------------
//
void C$(classname)View::HandleCommandL(TInt aCommand)
	{   
	switch ( aCommand )
		{
		case EAknSoftkeyOk:
			{
			iEikonEnv->InfoMsg( _L("$(classname)View ok") );
			break;
			}
		case EAknSoftkeyBack:
			{
			AppUi()->HandleCommandL(EEikCmdExit);
			break;
			}
		case ECmd$(classname)ViewCommand:
			{
			iEikonEnv->InfoMsg( _L("$(classname)View ok from command") );
			break;
			}
		default:
			{
			AppUi()->HandleCommandL( aCommand );
			break;
			}
		}
	}

// ---------------------------------------------------------
// C$(classname)View::HandleClientRectChange()
// ---------------------------------------------------------
//
void C$(classname)View::HandleClientRectChange()
	{
	if ( iContainer )
		{
		iContainer->SetRect( ClientRect() );
		}
	}

// ---------------------------------------------------------
// C$(classname)View::DoActivateL(...)
// 
// ---------------------------------------------------------
//
void C$(classname)View::DoActivateL(
	const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
	const TDesC8& /*aCustomMessage*/)
	{
	if (!iContainer)
		{
		iContainer = new (ELeave) C$(classname)Container;
		iContainer->SetMopParent(this);
		iContainer->ConstructL( ClientRect() );
		AppUi()->AddToStackL( *this, iContainer );
		} 
	}

// ---------------------------------------------------------
// C$(classname)View::DoDeactivate()
// 
// ---------------------------------------------------------
//
void C$(classname)View::DoDeactivate()
	{
	if ( iContainer )
		{
		AppUi()->RemoveFromViewStack( *this, iContainer );
		}
	
	delete iContainer;
	iContainer = NULL;
	}

